import java.util.Arrays;

/**
 * Created with IntelliJ IDEA
 * Description
 * User:user
 * Date:2021-10-18
 * Time:10:10
 */
public class TestDemo {

//4中数组拷贝方法
    public static int[] fun1(int[] arry){
        int[] ret = new int[arry.length];
        for (int i = 0; i < arry.length; i++) {
            ret[i] = arry[i];
        }
        return ret;
    }
    //Arrays.toString(arry)
    //Arrays.sort(sort)
    //Arrays.fill(arry,9)
    //Arrys.fill(arry,2,3,1)
    //Arrays.copeOf(arry)
    //Arrays.copeOfRange(arry)
	//深拷贝 浅拷贝 会在接口的地方进行讲解
	//native修饰的是本地方法，表示的他的底层是由c  c++实现的，运行速度特别快，看不到底层的实现
    public static void main(String[] args) {
        int[] arry = {1,2,3,4,5};
        System.out.println(Arrays.toString(fun1(arry)));
        System.out.println(Arrays.toString(Arrays.copyOf(arry,arry.length)));
        System.out.println(Arrays.toString(Arrays.copyOf(arry,2*arry.length)));//扩容函数
        System.out.println(Arrays.toString(Arrays.copyOfRange(arry,1,3)));
        //你要拷贝的数组  你要拷贝的数组的起始位置
        int[] ret = new int[arry.length];
        System.arraycopy(arry,0,ret,0,arry.length);
        //System.arraycopy(arry,0,ret,0,2*arry.length);//报错因为指的是需要拷贝的长度，如果长度太大，那么就有可能越界
        System.out.println(Arrays.toString(ret));
        System.out.println(Arrays.toString(arry.clone()));//调用的副本，产生了一个指向的对象的副本
    }






    //将所有的奇数放到数组的后面
    //偶数放到前面奇数放到后面
    //当j遇到偶数i遇到奇数才进行交换
    //i可能一直往后走，直到最后
    //j一直往前走，直到最前面


//    public static void func3(int[] arry){
//        int i = 0;
//        int j = arry.length - 1;
//        while(i < j){
//            while(i<j&&arry[i] % 2 == 0){
//                i++;
//            }
//            while(i<j&&arry[j] % 2 != 0){
//                j--;
//            }
//            int tmp = arry[i];
//            arry[i] = arry[j];
//            arry[j] = tmp;
//        }
//
//    }
//
//
//    public static void main(String[] args) {
//        int[] arry = {4,5,1,2,3,8,6,4};
//        func3(arry);
//        System.out.println(Arrays.toString(arry));
//    }

/*

    public static void reverse(int[] arry){
        int left = 0;
        int right = arry.length - 1;
        while(left < right){
            int tmp = arry[left];
            arry[left] = arry[right];
            arry[right] = tmp;
            left++;
            right--;
        }
    }

    public static void main(String[] args) {
        int[] arry = {5,4,6,7,8,9};
        reverse(arry);
        System.out.println(Arrays.toString(arry));
    }
*/



    
    
/*

    public static int[] func(int[] arry,int target){
        int[] ret = {-1,-1};
        for (int i = 0; i < arry.length; i++) {
            for (int j = i+1; j < arry.length; j++) {
                if(arry[i] + arry[j] == target){
                    ret[0] = i;
                    ret[1] = j;
                    return ret;
                }
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        int[] arry = {1,2,5,3};
        System.out.println(Arrays.toString(func(arry,3)));
    }
*/



 /*   void find_num(int arr[], int len)
    {
        int i = 0;//循环变量
        int ret = 0;//记录所有值异或的结果
        int pos = 0;//记录ret二进制为第一个为1的位置
        int x = 0;//将一组值异或在x，得到1个没有相同数字的值
        int y = 0;//将另一组值异或在x，得到另1个没有相同数字的值
        for (i = 0; i < len; i++)
        {
            ret ^= arr[i];
        }//将数组的所有值异或
        for (i = 0; i < 32; i++)
        {
            if (1 == ((ret >> i) & 1))
            {
                pos = i;
                break;
            }
        }//找到ret二进制为第一个为1的位置
        for (i = 0; i < len; i++)
        {
            if (1 == ((arr[i] >> pos) & 1))
            {
                x ^= arr[i];
            }
            else
                y ^= arr[i];
        }//分组异或
        printf("x=%d,y=%d\n", x, y);

    }
    int main()
    {
        int arr[] = { 1, 2, 3, 1, 2, 3, 4, 5 };
        int sz = sizeof(arr) / sizeof(arr[0]);
        find_num(arr, sz);
        system("pause");
        return 0;
    }

*/





/*    public static int fun(int[] arry){
        //0^n结果是n
        //1^n结果是0
        int sum = 0;
        for (int i = 0; i < arry.length; i++) {
            sum = sum ^ arry[i];
        }
        return sum;
    }

    public static int fun(int[] arry){

        for (int i = 0; i < arry.length; i++) {
            int count = 0;
            for (int j = i; j < arry.length; j++) {
                if(arry[j] == arry[i]){
                    count++;
                }
            }
            if(count == 1){
                return arry[i];
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arry = {1,2,3,3,2};
        System.out.println(fun(arry));
    }
*/


/*    public static int fun(int[] arry){
        int winner = arry[0];
        int people = 1;
        for (int i = 1; i < arry.length ; i++) {
            if(arry[i]==winner){
                people++;
            }else{
                if(people != 0){
                    people--;
                }else{
                    winner = arry[i];
                    people++;
                }
            }
        }
        return winner;
    }

    public static void main(String[] args) {
        int[] arry = {1,1,1,2};
        System.out.println(fun(arry));
    }*/


/*
    public int majorityElement(int[] nums) {
//2.参考题解思路的摩尔投票法
        int winer = nums[0];
        int people = 1;//目前主导势力的人数
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == winer) {
//如果是是自己人 势力增强
                people++;
            } else {
//如果是敌人 且目前主导势力还有士兵 则主导势力人数减少
                if (people != 0) {
                    people--;
                } else {
//如果主导势力已经没有士兵 则主导势力转移 人数增加
                    winer = nums[i];
                    people++;
                }
            }
        }
        return winer;//最后的胜者就是众数
    }
*/



/*
    //查找数组中出现次数最多且大于总个数的一半
    public static int func(int[] arry){
        for (int i = 0; i < arry.length; i++) {
            int count = 0;
            for (int j = i; j < arry.length; j++) {
                if(arry[i] == arry[j]){
                    count++;
                }
            }
            if(count>arry.length/2){
                return arry[i];
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arry = {1,2,3,2,2,2};
        System.out.println(func(arry));
    }
*/



/*

    public  static boolean fun(int[] arry){
        int count = 0;
        for (int i = 0; i < arry.length; i++) {
            if((arry[i]&1)==1){
                count++;
            }else{
                count = 0;
            }
            if(count == 3){
                return true;
            }
        }
        return false;

    }
*/


/*
    public static boolean fun(int[] arry){
        for (int i = 0; i < arry.length - 2; i++) {
            int count = 0;
            for (int j = i; j < i+3; j++) {
                if((arry[i] & 1)==1){
                    count++;
                }else{
                    break;
                }
            }
            if(count == 3){
                return true;
            }
        }
        return false;
    }
*/




/*    public static boolean fun(int[] arry){
        for (int i = 0; i < arry.length - 2; i++) {
            if((arry[i]%2==1)&&(arry[i+1]%2==1&&(arry[i+2]%2==1))){
                return true;
            }
        }
        return false;
    }*/


//
//    public static boolean fun(int[] arry){
//        if(arry.length < 3){
//            return false;
//        }
//        for (int i = 0; i < arry.length - 2; i++) {
//            int count = 0;
//            for (int j = i; j < i + 3 ; j++) {
//                if(arry[i] % 2 != 0){
//                    count++;
//                }else {
//                    break;
//                }
//            }
//            if(count == 3){
//                return true;
//            }
//        }
//        return false;
/*
//    }

    public static void main(String[] args) {
        int[] arry = {1,3,5,7};
        System.out.println(fun(arry));
    }
*/



/*  非递归迭代的实现
    public static int frogJump(int n ){
        if(n == 1){
            return 1;
        }
        if(n == 2){
            return 2;
        }
        int a = 1;
        int b = 2;
        int c = 0;
        for (int i = 3; i <= n; i++) {
            c = a + b;
            a = b;
            b = c;
        }
        return c;
    }*/

 /*   //青蛙跳台阶frog
    public static int frogJump(int n){
        if(n == 1){
            return 1;
        }
        if(n == 2){
            return 2;
        }
        return frogJump(n -1) + frogJump(n - 2);
    }

    public static void main(String[] args) {
        System.out.println(frogJump(1));
        System.out.println(frogJump(2));
        System.out.println(frogJump(3));
        System.out.println(frogJump(4));
    }*/



 /*   //判断数组中是否有三个连续的奇数
    public static boolean fun1(int[] arry){
        for (int i = 0; i < arry.length - 2; i++) {
            if((arry[i] % 2 == 1)&&(arry[i+1] % 2 == 1)&&(arry[i+2]%2 == 1)){
                return true;
            }
        }
        return false;
    }
    public  static  boolean fun2(int[] arry){
        for (int i = 0; i < arry.length - 2; i++) {
            int j = 0;
            for (j = i; j <= i + 2 ; j++) {
                if(arry[j]%2==0){
                   break;
                }
            }
            if(j > i + 2){
                return true;
            }
        }
        return false;
    }
    public static boolean fun3(int[] arry){
        for (int i = 0; i < arry.length - 2; i++) {
            int count = 0;
            for (int j = i; j <= i + 2 ; j++) {
                if((arry[i] & 1) == 1){
                    count++;
                }
            }
            if(count == 3){
                return true;
            }
        }
        return false;

    }

    public static void main(String[] args) {
        int[] arry = {1,5,7,9,48};
        System.out.println(fun3(arry));
    }
*/
 /*   //递归实现但是当数字特别大的时候会重复计算很多次，效率不是很高
    public static int frogJump1(int n ){
        if(n == 1){
            return 1;
        }if(n == 2){
            return 2;
        }
        return frogJump1(n - 1) + frogJump1(n - 2);
    }


    //shift+F6会改变所有出现的变量值
    //非递归实现，推荐使用
    public static int frogJump2(int n){
        if(n == 1){
            return 1;
        }
        if(n == 2){
            return 2;
        }
        int a = 1;
        int b = 2;
        int c = 0;
        for (int i = 3; i <= n; i++) {
            c = a + b ;
            a = b;
            b = c;
        }
        return c;
    }
    public static void main(String[] args) {
        System.out.println(frogJump1(1));
        System.out.println(frogJump1(2));
        System.out.println(frogJump1(3));
        System.out.println(frogJump1(4));
        System.out.println(frogJump2(1));
        System.out.println(frogJump2(2));
        System.out.println(frogJump2(3));
        System.out.println(frogJump2(4));
    }*/


}
